;**************************************************************
;	
;	This an simple test of  led for S3C2440
;	Hope it is useful to you.
;		 app :		 		asm_led_boot
;
;	   Board:				akae2440
;    environment:	bootloader & ADS
;    Author:			xingwenpeng
;    Date:				2009-7-20
;    web:					www.akaedu.org
;	
;		 CPLD_LED		physical address is	0x20800000
;
;**************************************************************	

	AREA    Init, CODE, READONLY

	ENTRY

start
;**************************************
; 1.disabble Watch dog                *
;**************************************	

disabble_watch_dog
	mov r1,#0x53000000
	mov r2,#0x0
	str r2,[r1]

;**************************************
; 2.disabble Interrupt                *
;**************************************

disablle_interrupt
	ldr r1,=0x4a000008
	mov r2,#0xffffffff
	str r2,[r1]
	
;**************************************
; 3.clock set FCLK=304MHz             *
;   FCLK:HCLK:PCLK = 6:3:1            *   
;   UCLK = 48MHz                      *
;**************************************
	
clock_set

;MMU_setAsyncBusMode  
	mrc p15,0,r1,c1,c0,0
	orr r1,r1,#0xc0000000
	mcr p15,0,r1,c1,c0,0
	
	;CAMDIVN
	ldr r0,=0x4c000018
	mov r1,#0x0
	str r1,[r0]
	
	
	;LOCKTIME PLL
	ldr r0,=0x4c000000
	ldr r1,=0x00ffffff
	str r1,[r0]
	
	;UPLLCON
	ldr r0,=0x4c000008
	ldr r1,=0x00038022
	str r1,[r0]
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	
	;MPLLCON
	ldr r0,=0x4c000004
	ldr r1,=0x00044011
	str r1,[r0]
	
	;CLKCON
	ldr r0,=0x4c00000c
	ldr r1,=0x00fffff0
	str r1,[r0]
	
	;CLKSLOW
	ldr r0,=0x4c000010
	ldr r1,=0x00000004
	str r1,[r0]
	
	;CLKDIVN
	ldr r0,=0x4c000014
	ldr r1,=0x00000007
	str r1,[r0]

;**************************************
; 4.Init sdram                        *
;**************************************

memsetup
	ldr r1,=MEM_CTL_BASE  
	adrl r2,mem_cfg_val   
	add r3,r1,#52
1
	ldr r4,[r2],#4
	str r4,[r1],#4
	cmp r1,r3
	bne %1
	nop
	nop
	nop
	nop

MEM_CTL_BASE EQU 0X48000000

mem_cfg_val
	DCD 0x22111110
	DCD 0x00000700
	DCD 0x00000700
	DCD 0x00000700
	DCD 0x00000700
	DCD 0x00000700
	DCD 0x00000700
	DCD 0X00018005
	DCD 0X00018005
	DCD 0X008E0459
	DCD 0X000000B1
	DCD 0X00000030
	DCD 0X00000030
	
;**************************************
; 5.beep_off                          *
;**************************************
	
beep_off
	ldr r0,=0x56000010
	mov r1,#0x1
	str r1,[r0]

	ldr r0,=0x56000014
	ldr r1,[r0]
	bic r1,r1,#0x1
	str r1,[r0]
	
;**************************************
; 6.led_test                          *
;**************************************	

	;test 3 times
	mov r4,#3
led_test
	ldr r0, =0x20800000
	mov r1, #0xff
	strb r1, [r0]

	ldr r0 ,=0xfffff
delay0
	sub r0,r0,#1
	cmp r0,#0
	bne delay0
	
	ldr r0, =0x20800000
	mov r1, #0x0
	strb r1, [r0]

	ldr r0 ,=0xfffff
delay1
	sub r0,r0,#1
	cmp r0,#0
	bne delay1
	
	sub r4,r4,#1
	cmp r4,#0
	bne led_test
	
	
;**************************************
; 7.test sdram read/write             *
;**************************************		

sdram_test
	ldr r1,=0x123456
	ldr r2,=0x30001000
	str r1,[r2]	
	
;***************************************
; 8.copy myself from nandflash to sdram*
;***************************************
		
	;set sdram stack for C app
	ldr sp,=0x33ef0000
	
	IMPORT copy_myself
	
;nand_begin=0x0 
;size=0x20000
;sdram_begin=0x33f00000
	
	bl copy_myself
	
		ldr r1,=on_the_ram
	add pc,r1,#0
	nop
	nop
	nop

on_the_ram
	
;**************************************
; 8.set ram stack for C app           *
;**************************************	

	IMPORT c_entry
	
	ldr sp, =0x33ef0000
	b c_entry
	
	end